<?php

/**
 * Flickr Photosets - Library
 * This file should be included from every page. It includes all necessary files for the app.
 * 
 * @author Brad Dougherty <bdougherty@gmail.com>
 * @version 8.6.14
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 3.0
 */

/*
Change this to bring the app down.
*/
define('APP_DOWN', false);

/*
Include the database connection information
Defines constants DB_TYPE, DB_HOST, DB_NAME, DB_TABLE, DB_USER, DB_PASS,
FACEBOOK_API_KEY, FACEBOOK_API_SECRET, FLICKR_API_KEY,
FLICKR_API_SECRET, GOOGLEMAPS_API_KEY, GOOGLE_ANALYTICS_ACCOUNT,
CACHE_DIR, REVISION
*/
require_once 'config.php';

/*
Include the Facebook client library
*/
require_once 'libs/facebook/facebook.php';

/*
Include the phpFlickr library
Current version: 2.1.0
*/
require_once 'libs/phpFlickr/phpFlickr.php';

/**
 * Autoload the classes as needed, all are located in classes subdir
 * @param string $class_name The class to load
 */
function __autoload($class_name) {
	if (substr($class_name, 0, 3) == 'FP_') {
		// FP_ClassName
		$class_file = 'classes/'.substr($class_name, 3).'.php';
	}
	else {
		// Other Classes
		$class_file = 'classes/'.$class_name.'.php';
	}
	
	require_once $class_file;
}

/*
Turn Facebook library debugging off
*/
$globals['facebook_config']['debug'] = false;

/*
Use stylesheet link or include file
*/
define('USE_STYLESHEET_INCLUDE', false);

/*
Turn on error reporting
You can either change this variable to true or append ?showerrors to the url.
*/
$error_reporting = false;
if (isset($_GET['showerrors']) or $error_reporting) {
	error_reporting(E_ALL);
	ini_set('display_errors', 1);
	$globals['facebook_config']['debug'] = true;
}

// Error handler
// Will eventually be set to hide info such as filename from the user
//error_reporting(0);
function error_handler($error_number, $error_string, $file, $line_number) {
	
	$error_types = array(
		E_ERROR              => 'Error',
		E_WARNING            => 'Warning',
		E_PARSE              => 'Parsing Error',
		E_NOTICE             => 'Notice',
		E_CORE_ERROR         => 'Core Error',
		E_CORE_WARNING       => 'Core Warning',
		E_COMPILE_ERROR      => 'Compile Error',
		E_COMPILE_WARNING    => 'Compile Warning',
		E_USER_ERROR         => 'User Error',
		E_USER_WARNING       => 'User Warning',
		E_USER_NOTICE        => 'User Notice',
		E_RECOVERABLE_ERROR  => 'Catchable Fatal Error'
	);
	$die_errors = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_RECOVERABLE_ERROR);
	
	$error = 'Error '.$error_types[$error_number].' on line '.$line_number.' of '.$file.' : '.$error_string;
	error_log($error, 1, 'bdougherty+fperrors@gmail.com');
	
	if (in_array($error_number, $die_errors)) {
		echo '<b>Uh oh, an error occurred.</b> It has been logged and will be fixed as soon as possible.';
	}
	
}
//set_error_handler("error_handler");

?>